/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package itcast;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.Locale;

/**
 * <p>Project: JavaStudy - LocalDateDemo
 * <p>Powered by jiangbo On 2023-02-01
 * 21:41:12
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class LocalDateDemo {
    public static void main(String[] args) {
//实例化
        LocalDate d1 = LocalDate.now();
        var d2 = LocalDate.of(1985,10,17);
//常用操作
//今日5天后日期
        System.out.println(d1.plusDays(5));
//今日3天前日期
        System.out.println(d1.minusDays(3));
//今日25个月后的新日期
        System.out.println(d1.plus(25, ChronoUnit.MONTHS));
//今日日期的月份 中文效果： 十月
        System.out.println(d1.getMonth().getDisplayName(TextStyle.FULL,Locale.CHINESE));
//今日 星期一
        System.out.println(d1.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.CHINESE));
//今日 周一
        System.out.println(d1.getDayOfWeek().getDisplayName(TextStyle.SHORT,Locale.CHINESE));
//计算两个日期之间的天数
        long days = ChronoUnit.DAYS.between(d2,d1);
        System.out.printf("%s 到 %s 之间有 %d 天",d2,d1,days);
        System.out.println();
//格化输出
        System.out.println(d1);
        System.out.println(d2);
        System.out.printf("%tF%n",d1);
        System.out.printf("%tF%n",d2);
        System.out.printf("%tY年%<tm月%<td日 %<tA%n",d1);
        System.out.printf("%tY年%<tm月%<td日 %<tA%n",d2);
        System.out.println(d1.isLeapYear());
//专业的格式工具类
//DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy年MM月dd日 E M L");
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy年 MM月dd日 E M L", Locale.CHINA);
                System.out.println(fmt.format(d1));
        System.out.println(fmt.format(d2));
        //当前日期
        System.out.println(LocalDate.now());
//10个月后的日期
        System.out.println(LocalDate.now().plusMonths(10));
//10个月后的那个月的最后一天日期
        System.out.println(LocalDate.now().plusMonths(10).with(TemporalAdjusters.lastDayOfMonth()));
//LocalDate localDate = LocalDate.now();
        LocalDate localDate =LocalDate.of(2020, 2, 20);
        System.out.println("localDate = " + localDate);
//当月最后一天
        LocalDate lastDay = localDate.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("lastDay = " + lastDay);
        //当月第一天
        LocalDate firstDay =
                localDate.with(TemporalAdjusters.firstDayOfMonth());
        System.out.println("firstDay = " + firstDay);
//计算两个日期有多少个月 5 6 7 8 9 10 11 12 1
        LocalDate a = LocalDate.of(2022,5,13);
        LocalDate b = LocalDate.now();
//两个日期多少天
        System.out.println(ChronoUnit.DAYS.between(a,b));
        System.out.println(ChronoUnit.DAYS.between(b,a));
//两个日期多少个月
        System.out.println(ChronoUnit.MONTHS.between(a,b));
        System.out.println(a.plusMonths(8));

    }

    }


